var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var ObjectId = Schema.ObjectId;

var TopicSchema = new Schema({
	title: String,
	content: String,
	authorId: ObjectId,
	tabId: ObjectId,
	tags: { type: Array, default: [] },
	views: { type: Number, default: 0 },
	isStarred: { type: Boolean, default: false },
	lastReplyAt: Date,
	lastUpdateAt: { type: Date, default: new Date() },
	createAt: { type: Date, default: new Date() }
});

TopicSchema.index({ createAt: -1 });
TopicSchema.index({ createAt: -1, lastUpdateAt: -1 });

mongoose.model('Topic', TopicSchema);